#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,mod,ans[10] = {0,1,6,66,1064,22680,602352,19176304};
signed main()
{
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n>>mod;
	cout<<ans[n]%mod;
	return 0;
}

